/**
 * This Class is used to do some validation and define some configuration for Email
 */
package com.oet.service.mail;

import javax.mail.MessagingException;

import org.apache.commons.validator.EmailValidator;

import com.oet.persistence.entity.Customer;

//import com.ydk.account.persistence.entity.Reader;

/**
 * @author y140zhan
 *
 */
public class EmailUtility {
	
	public final static String EMAIL_DEFAULT_CHARSET = "UTF-8";
	
	public final static String EMAIL_DEFAULT_MIMETYPE = "text/html";
	
	public final static String EMAIL_DEFAULT_FROMADDR = "yu.zhang@nsn.com";
	
	public final static String EMAIL_DEFAULT_FROMNAME = "瑞德专业英语培训";
	public final static String EMAIL_TAIL_CONTENT = 
	"<br/><b>快速访问瑞德专业英语培训点击这里</b>：<a href=\"www.readyforabc.com\">www.readyforabc.com</a>"
	+ "<br/><br/>瑞德专业英语培训为您开启未来成功之门，我们竭力为您提供全方位的服务。" 
	+"<br/>现在，准备开始了吗？</b></p>";
	
	public static boolean isValid(String address) {
        return EmailValidator.getInstance().isValid(address);
    }
	

//	public static void sendRegisterEmail(EmailServiceInterface mailService, Customer reader) {
//		YdkMail ydkMail = mailService.getYdkMail(reader.getEmail(), 
//				"Your Ydk account's password ", true);
//		
//		ydkMail.setContent("Dear " + reader.getNickName() + ":<br/>" 
//				+ "Your password of ydk account: " + reader.getNickName() 
//				+ " is to: <b>" + reader.getPassword() + "</b>.<br/>"
////				+ "<br/>Please click the following link to enable your account: <br/><br/>"
////				+ "<a href=\"/>"
//				);
//		
//		//If enable mail activation mechanism, then we need to remove the following thing;
//		reader.setIsActived(true);
//		
//		
//
//		try {
//			mailService.send(ydkMail);
//		} catch (MessagingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//    }
	
	public static void sendRegisterEmailCn(EmailServiceInterface mailService, Customer entry) {
		MailInfo mail = mailService.getMailInfo(entry.getEmail(), 
				"欢迎成为瑞德专业英语培训，一起分享阅读", true);
		
		mail.setContent("亲爱的 " + entry.getEmail() + ":<br/>" 
				+ "恭喜您成为众多瑞德专业英语培训中的一员，您在瑞德专业英语培训的账户是: " + entry.getEmail()  +"，"
				+ "密码是: <b>" + entry.getPassword() + "</b>，请您记住它，以让你更好地体验我们的系列产品。<br/>"
				+ EMAIL_TAIL_CONTENT
				);
		
		//If enable mail activation mechanism, then we need to remove the following thing;
		entry.setIsActived(true);
		
		

		try {
			mailService.send(mail);
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	
	
	public static void sendForgetPasswordEmailCn(EmailServiceInterface mailService, Customer entry) {
		MailInfo mail = mailService.getMailInfo(entry.getEmail(), 
				"瑞德专业英语培训密码重置", true);
		
		mail.setContent("尊敬的 " + entry.getName() + ":<br/>" 
				+ "密码重置成功，您在瑞德专业英语培训的账户是: " + entry.getEmail()  +"，"
				+ "密码是: <b>" + entry.getPassword() + "</b>，请您记住它，以让你更好地体验我们的系列产品。<br/>"
				+ EMAIL_TAIL_CONTENT
				);
		
		//If enable mail activation mechanism, then we need to remove the following thing;
		entry.setIsActived(true);
		
		

		try {
			mailService.send(mail);
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }


}
